<template>
  <!--
      作者：luoyiming
      时间：2019-10-25
      描述：售后管理
  -->
  <div class="user">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="订单号">
          <el-input v-model="formInline.order_no" placeholder="请输入订单号"></el-input>
        </el-form-item>
        <!--        <el-form-item label="售后类型">-->
        <!--          <el-select v-model="formInline.type" placeholder="请选择">-->
        <!--            <el-option label="全部" value="0"></el-option>-->
        <!--            <el-option label="退货退款" value="10"></el-option>-->
        <!--            <el-option label="换货" value="20"></el-option>-->
        <!--            <el-option label="仅退款" value="30"></el-option>-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="起始时间">-->
        <!--          <div class="block">-->
        <!--            <span class="demonstration"></span>-->
        <!--            <el-date-picker v-model="formInline.create_time" type="daterange" value-format="yyyy-MM-dd"-->
        <!--                            range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>-->
        <!--          </div>-->
        <!--        </el-form-item>-->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit()">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="全部售后" name="-1"></el-tab-pane>
          <el-tab-pane :label="'进行中'" name="1"></el-tab-pane>
          <el-tab-pane :label="'已完成'" name="2"></el-tab-pane>
          <el-tab-pane :label="'已拒绝'" name="3"></el-tab-pane>
          <!--          <el-tab-pane :label="'已取消(' + (arr[30] ? arr[30].total : 0) + ')'" name="30"></el-tab-pane>-->
        </el-tabs>
        <el-table :data="tableData" border style="width: 100%" v-loading="loading">
          <el-table-column prop="order_no" label="订单号" width="130">
            <template slot-scope="scope">
              <p class="gray6" style="color: blue; cursor: pointer;" @click="addClick( scope.row.order_id)">
                {{ scope.row.order_no }}
              </p>
            </template>
          </el-table-column>
          <el-table-column prop="orderproduct.product" label="商品">
            <template slot-scope="scope">
              <div v-for="item in scope.row.product">
                {{ item.product_name }} x {{ item.total_num }}
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="store.store_name" label="所属门店"></el-table-column>
          <!--          <el-table-column prop="create_time" label="时间" width="200">-->
          <!--            <template slot-scope="scope">-->
          <!--              <p class="gray6">-->
          <!--                <span class="gray9">售后申请：</span>-->
          <!--                {{ scope.row.create_time }}-->
          <!--              </p>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <!--           <el-table-column prop="create_time" label="下单时间">-->
          <!--             <template>-->
          <!--               {{scope.row.create_time}}-->
          <!--             </template>-->
          <!--           </el-table-column>-->
          <el-table-column prop="orderproduct.product_price" label="总价">
            <template slot-scope="scope">
              <span class="orange">{{ scope.row.total_price }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="orderproduct.product_price" label="售后状态">
            <template slot-scope="scope">
              <span class="orange" v-if="scope.row.is_order_refund == 1">进行中</span>
              <span class="orange" v-if="scope.row.is_order_refund == 2">已完成</span>
              <span class="orange" v-if="scope.row.is_order_refund == 3">已拒绝</span>
            </template>
          </el-table-column>
          <el-table-column prop="orderproduct.product_price" label="提交时间">
            <template slot-scope="scope">
              <span class="orange">{{ scope.row.refund_time }}</span>
            </template>
          </el-table-column>
          
          <el-table-column prop="refund_audit_time" label="处理时间"></el-table-column>
          <!--          <el-table-column prop="orderproduct.total_pay_price" label="付款价"></el-table-column>-->
          <el-table-column fixed="right" label="操作" width="110">
            <template slot-scope="scope">
              <p>
                <el-button @click="Detail(scope.row.order_id)" type="text" size="small">售后详情</el-button>
              </p>
              <!-- <p>
                <el-button v-if="supplier.is_after_sale ==0 && scope.row.is_order_refund == 1" @click="Detail(scope.row.order_id)" type="text"
                           size="small">去审核
                </el-button>
              </p> -->
              <!--                        <p>-->
              <!--                          <el-button-->
              <!--                            v-if="scope.row.type.value != 30 && scope.row.is_agree.value == 10 && scope.row.is_receipt == 0 && scope.row.is_user_send == 1"-->
              <!--                            @click="Detail(scope.row.order_refund_id)" type="text" size="small">-->
              <!--                            处理-->
              <!--                          </el-button>-->
              <!--                        </p>-->
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--分页-->
      <div class="pagination">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background
                       :current-page="curPage" :page-sizes="[2, 10, 20, 50, 100]" :page-size="pageSize"
                       layout="total, sizes, prev, pager, next, jumper" :total="totalDataNumber"></el-pagination>
      </div>
    </div>

    <order-detail :show-detail.sync="showDetail" :order_id="order_id"></order-detail>
  </div>
</template>

<script>
import OrderApi from '@/api/order.js';
import IndexApi from "@/api/index.js";
import OrderDetail from '@/components/order/OrderDetail.vue';

export default {
  components: {
    OrderDetail
  },
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        order_no: '',
        style_id: '',
        shop_id: '',
        create_time: '',
        status: 0,

      },
      store:[],
      status: -1,
      arr: [],
      supplier: {is_after_sale: 1},
      activeName: '-1',
      order_id: 0,
      showDetail:false
    };
  },
  created() {
    if(this.$route.query.status){
      this.status =  this.$route.query.status;

    }
    this.activeName = this.status.toString();
    /*获取列表*/
    this.getTableList();
    this.getSupplier();
  },


  methods: {

    addClick(order_id) {
      console.log('订单ID',order_id)
      this.order_id = order_id;
      this.showDetail = true;
    },
    getSupplier() {
      let self = this;
      IndexApi.base({}, true)
        .then(data => {
          self.supplier = data.data.settings.supplier
        })
        .catch(error => {
        });
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      this.curPage = val;
      this.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    /*切换菜单*/
    handleClick(tab, event) {
      this.curPage = 1;
      this.status = tab.name;
      this.getTableList();
    },

    /*获取列表*/
    getTableList(params = '') {
      let self = this;
      let Params = {};
      Params.status = self.status;
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      if (params != '') {
        Params.order_no = params.order_no;
        Params.create_time = params.create_time;
        Params.type = params.type;
      }
      self.loading = true;
      self.tableData = [];
      OrderApi.orderrefund(Params, true)
        .then(data => {
          self.loading = false;
          self.tableData = data.data.list.data;
          self.totalDataNumber = data.data.list.total;
          self.exStyle = data.data.ex_style;
          self.shopList = data.data.shopList;
          self.arr = data.data.arr;
        })
        .catch(error => {
        });
    },

    /*搜索查询*/
    onSubmit() {
      let self = this;
      let Params = this.formInline;
      self.getTableList(Params);
    },

    /*详情*/
    Detail(e) {
      let self = this;
      let order_id = e;
      this.$router.push({
        path: '/order/refund/Detail',
        query: {
          order_id: order_id
        }
      });
    }
  }
};
</script>
<style></style>
